package com.frinder.official.akka.typed;

import akka.typed.ActorRef;
import akka.typed.ActorSystem;
import akka.typed.javadsl.AskPattern;
import akka.util.Timeout;

import java.util.concurrent.CompletionStage;
import java.util.concurrent.TimeUnit;

/**
 * Created by frinder on 2017/9/13.
 */
public class Test {

    public static void main(String[] args) {
        final ActorSystem<HelloWorld.Greet> system =
                ActorSystem.create(HelloWorld.greeter, "hello");

        final CompletionStage<HelloWorld.Greeted> reply =
                AskPattern.ask(system,
                        (ActorRef<HelloWorld.Greeted> replyTo) -> new HelloWorld.Greet("world", replyTo),
                        new Timeout(3, TimeUnit.SECONDS), system.scheduler());

        reply.thenAccept(greeting -> {
            System.out.println("result: " + greeting.whom);
            system.terminate();
        });
    }

}
